package com.spingweb.controller.rest;

import com.spingweb.dto.BookAuthor;
import com.spingweb.service.BookAuthorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * url到资源的映射。
 * 给用户一个表单，把信息填写进去。
 */
@RestController
@RequestMapping("/bookAuthor")
public class BookAuthorController {
    @Autowired
    BookAuthorService bookAuthorService;

    /**
     * @ ResponseBody注解会自动将注解object转换为json字符串
     */
    @GetMapping("/add")
    public String add() {

        return "bookAuthor/add";
    }

    @PostMapping("/add")
    public BookAuthor add(BookAuthor bookAuthor) {
        bookAuthorService.add(bookAuthor);
        return bookAuthor;
    }

    @GetMapping("/select")
    public List<BookAuthor> select() {
        return bookAuthorService.selectByCountry("中国");
    }
}
